home *** CD-ROM | disk | FTP | other *** search
/ BBS in a Box 12 / BBS in a box XII-1.iso / Files / Tele / T / Terminal 1.7.sit / Terminal scripts / Sieve.s < prev   
Encoding:
Text File  |  1989-11-06  |  1.4 KB  |  62 lines  |  [TEXT/QED1]

  1. /*
  2.     Terminal 1.7
  3.     "Sieve.s"
  4.  
  5. This script was used to test the "Terminal" script interpreter. It is of no
  6. practical use. It is the standard sieve benchmark often used to test the
  7. performance of computers. Note that because the "Terminal" script language
  8. is an interpreted language it is rather slow for loop intensive operations,
  9. but for its intended purpose as a communications script language it is fast
  10. enough.
  11.  
  12. The timing results were as follows (compared to the same program compiled
  13. with a real C compiler)
  14.  
  15.     Macintosh IIcx: 113 seconds (THINK C:  43.2 ms ==> 2616 times faster)
  16.     Macintosh Plus: 527 seconds (THINK C: 271.0 ms ==> 1945 times faster)
  17.  
  18. */
  19.  
  20. int SIZE = 8191;
  21. int LAUF = 1;
  22. char FALSE = 0;
  23. char TRUE = 1;
  24.  
  25. main()
  26. {
  27.     int tick, iter, count, i, k, prime;
  28.     char *flags, *p;
  29.  
  30.     display("Sieve benchmark %i passes\rThis may take several minutes...\r",
  31.         LAUF);
  32.     if (!(flags = new(SIZE))) {
  33.         display("Not enough memory\r")
  34.         return;
  35.     }
  36.     tick = time();                            /* <====== start */
  37.  
  38.     for (iter = 0; iter < LAUF; ++iter) {
  39.         count = 0;
  40.         p = flags + SIZE;
  41.         while (p > flags)
  42.             *(--p) = TRUE;
  43.         /* p == flags */
  44.         for (i = 0; i < SIZE; ++i) {
  45.             if (*p) {
  46.                 k = i + (prime = i + i + 3);
  47.                 while (k < SIZE) {
  48.                     flags[k] = FALSE;
  49.                     k = k + prime;
  50.                 }
  51.                 ++count;
  52.                 /*display("%i\r", prime);*/
  53.             }
  54.             ++p;
  55.         }
  56.     }
  57.  
  58.     tick = time() - tick;                    /* <====== stop */
  59.     free(flags);
  60.     display("%i primes in %i seconds\r", count, tick);
  61. }
  62.